import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:yx_flutter/common/YXToastUtil.dart';
import 'package:yx_flutter/net/net_utils.dart';
import '../provider/base.dart';
import 'YXUpdatePasswordModel.dart';

class UpdatePasswordProvide extends BaseProvide {
  // 老密码
  final oldPasswordController = TextEditingController();
  // 新密码
  final newPasswordController = TextEditingController();
  // 确认新密码
  final ensurePasswordController = TextEditingController();

  // 接口返回结果
  UpdatePasswordModel responseModel;

  /// 改变密码
  void changePassword() {
    if (newPasswordController.text != ensurePasswordController.text) {
      ToastUtil.showBasicToast('请确认两新密码一致');
      return;
    }

    get("/api/resetPasswordByMobileNo", {
      "oldPassword": oldPasswordController.text, // 老密码
      "newPassword": newPasswordController.text // 新密码
    }).doOnListen(() {}).listen((event) {
      // 转化为模型
      responseModel = UpdatePasswordModel.fromJson(event);

      if (responseModel.respCode != 200) {
        ToastUtil.showBasicToast(
            'respCode:${responseModel.respCode},errorMsg:${responseModel.errorMsg}');
      } else {
        ToastUtil.showBasicToast('密码修改成功');
        notifyListeners();
      }
    });
  }
}
